#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace Test
{
    class AnimateTexture
    {
        private Texture2D spriteSheet;

        private float timer = 0f;
        private int currentFrame = 0;

        private int SpriteWidthS = 0;
        private int SpriteHeightS = 0;

        private Rectangle sourceRect;

        SpriteBatch spriteBatch;

        public void Load(ContentManager content, string Sprite)
        {
            spriteSheet = content.Load<Texture2D>(Sprite);
        }

        public void Animate(float fps, int numFrames, int SpriteWidth,
            int SpriteHeight, ContentManager content,
            GraphicsDeviceManager gdm, GameTime gameTime)
        {
            timer += gameTime.ElapsedGameTime.Milliseconds;
            float interval = 1000f / fps;

            if (timer > interval)
            {
                currentFrame++;

                if (currentFrame > numFrames - 1)
                {
                    currentFrame = 0;
                }
                timer = 0f;
            }
            sourceRect = new Rectangle(currentFrame * SpriteWidth, 0, SpriteWidth, SpriteHeight);

            SpriteHeightS = SpriteHeight;
            SpriteWidthS = SpriteWidth;
        }

        public void Draw(float XPos, float YPos, GraphicsDeviceManager gdm)
        {

            spriteBatch = new SpriteBatch(gdm.GraphicsDevice);

            Rectangle position;
            position = new Rectangle((int)XPos, (int)YPos, SpriteHeightS, SpriteWidthS);

            spriteBatch.Begin();
            spriteBatch.Draw(spriteSheet, position, sourceRect, Color.White);
            spriteBatch.End();
        }
    }
}
